package com.atguigu.edustatistics.controller;


import com.atguigu.commonutils.R;
import com.atguigu.edustatistics.service.StatisticsDailyService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 网站统计日数据 前端控制器
 * </p>
 *
 * @author 2516901039
 * @since 2023-01-30
 */
@RestController
@RequestMapping("/edustatistics/statistics-daily")
public class StatisticsDailyController {

    private static final Logger logger = LoggerFactory.getLogger(StatisticsDailyController.class);
    @Autowired
    private StatisticsDailyService statisticsDailyService;


    /**
     * 统计某一天的注册人数并添加
     * @param day
     * @return
     */
    @PostMapping("registerCount/{day}")
    public R registerCount(@PathVariable String day){
        logger.info("传过来的日期值为：{}",day);
        statisticsDailyService.registerCount(day);
        return R.ok();
    }

    /**
     * 图表显示，返回两部分数据，日期json数组没数量json数组
     * @param type
     * @param begin
     * @param end
     * @return
     */
    @GetMapping("showData/{type}/{begin}/{end}")
    public R showData(@PathVariable String type,
                      @PathVariable String begin,
                      @PathVariable String end){
        Map<String,Object> map=statisticsDailyService.getshowData(type,begin,end);
        return R.ok().data(map);
    }

}

